package com.leo.offer;

/**
 *
 * @author xuexiaolei
 * @version 2018年03月08日
 */
public class T17 {
    public static Node mergeSortedNode(Node n1, Node n2){
        Node head = new Node();
        Node temp = head;
        while (n1 != null && n2 != null){
            if (n1.val < n2.val){
                temp.next = n1;
                n1 = n1.next;
            }else {
                temp.next = n2;
                n2 = n2.next;
            }
            temp = temp.next;
        }
        if (n1 != null){ temp.next = n1; }
        if (n2 != null){ temp.next = n2; }
        return head.next;
    }

    public static void main(String[] args) {
        Node n1 = Node.createNode(new int[] {1, 2, 2, 3, 5, 7});
//        Node n1 = Node.createNode(new int[] {});
        Node n2 = Node.createNode(new int[] {2, 4, 6, 8});
//        Node n2 = Node.createNode(new int[] {});
        Node node = mergeSortedNode(n1, n2);
        Node.printNode(node);
    }
}
